package com.team.ai.service;

import com.team.ai.entity.Community;
import com.team.ai.entity.Concern;
import com.team.ai.entity.Like;
import com.team.ai.entity.ResultEntity;
import com.team.ai.mapper.CommunityMapper;
import com.team.ai.mapper.ConcernMapper;
import com.team.ai.mapper.LikeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LikeService {
    @Resource
    LikeMapper likeMapper;
    @Resource
    CommunityMapper communityMapper;
    public String insert(int userId,int likeId){
        try{
            return ResultEntity.success(likeMapper.insert(userId,likeId)) ;
        }catch (Exception e){
            e.printStackTrace();
            return  ResultEntity.fail(-10005);
        }
    }
    public String update(int likes,int id){
        try{
            return ResultEntity.success(likeMapper.update(likes, id)) ;
        }catch (Exception e){
            e.printStackTrace();
            return  ResultEntity.fail(-10005);
        }
    }
    public String delete(int userId,int likeId){
        try{
            return ResultEntity.success(likeMapper.delete(userId,likeId)) ;
        }catch (Exception e){
            e.printStackTrace();
            return  ResultEntity.fail(-10005);
        }
    }
    public String selectList(int userId){
        try{
            List<Like> likes=likeMapper.selectList(userId);
            List<Community> list = new ArrayList<>();
            for (Like like1:likes) {
                List<Community> community= communityMapper.selectByList(like1.getLikeid());
                for (Community community1 : community) {
                    community1.setIslike(1);
                }
                list.addAll(community);
            }
            return ResultEntity.success(list) ;
        }catch (Exception e){
            e.printStackTrace();
            return  ResultEntity.fail(-10005);
        }
    }



}
